﻿using System;
using NL.ADA.ConfigService.DAL.EntityClasses;
using NL.ADA.ConfigService.DAL.HelperClasses;
using NUnit.Framework;
using NL.ADA.Common;
using NL.ADA.ConfigAdmin;



namespace NUnit
{
    [TestFixture]
    public class UnitTestAdmin
    {
        [Test]
        public void GetAllConfigByAppId_Test()
        {
            var mgr = new NL.ADA.ConfigAdmin.ConfigManager();
            CustomConfigList result = mgr.GetAllConfigs(2, 0);
            Assert.That(result.Count == 2);

        }
        [Test]
        public void GetAllConfigByModeId_Test()
        {
            var mgr = new ConfigManager();
            CustomConfigList result = mgr.GetAllConfigs(0, 9);
            Assert.That(result.Count == 2);

        }
        [Test]
        public void GetAllConfigs()
        {
            ConfigManager mgr = new ConfigManager();
            EntityCollection collection = mgr.Get();
            Assert.That(collection.Count > 0);

        }
        
        
        [Test]
        public void InsertConfig_Test()
        {
            NL.ADA.ConfigAdmin.ConfigManager mgr = new NL.ADA.ConfigAdmin.ConfigManager();
            ConfigEntity entity = new ConfigEntity();
            entity.Key = "newKeyKesdfsdfysdfgsdfgKey" + DateTime.Now.ToString();
            entity.Value = "newValue";
            entity.ModeId = 9;
            entity.ConfigType = 1;
            entity.ApplicationId = 1;
            int result = mgr.Insert(entity);
            Assert.That(result > 0);
            
        }
        [Test]
        public void InsertConfigViaService_Test()
        {

            AdminServiceGateway gateWay = new AdminServiceGateway();
            int result = gateWay.InsertConfig(0, 9, "test_" + DateTime.Now.ToString(), "newValue", 1, String.Empty, 1);
            Assert.That(result > 0);

        }

        [Test]
        public void AdminSvc_Test()
        {
            NL.ADA.AdminService.AdminService svc = new NL.ADA.AdminService.AdminService();
            CustomConfig entity = new CustomConfig();
            entity.Key = "newKeyKesdfsdfysdfgsdfgKey" + DateTime.Now.ToString();
            entity.Value = "newValue";
            entity.ModeId = 9;
            entity.ConfigTypeId = 1;
            entity.ApplicationId = 1;

            int i = svc.InsertConfig(entity);

            Assert.That(i > 0);

        }

        void mgr_ServerModified(object sender, ServerModifiedEventArgs e)
        {
            object o = e;
        }

        public void UpdateConfig_Test()
        {
            ConfigManager mgr = new ConfigManager();
            ConfigEntity entity = new ConfigEntity();
            entity.Key = "newKey";
            entity.Value = "AnotherValue";
            entity.Description = "Test Value";
            entity.Id = 20;
            entity.ModeId = 9;
            entity.ConfigType = 1;
            entity.ApplicationId = 1;
            int result = mgr.Update(entity);
            Assert.That(result > 0);

        }

        [Test]
        public void InsertApplication_Test()
        {
            var mgr = new ApplicationManager();
            var entity = new ApplicationEntity();
            entity.AppCode = "test_app_code";
            entity.Description = "this is a test";
            entity.Created = DateTime.Now;
            entity.Modified = DateTime.Now;
            var result = mgr.Insert(entity);
            Assert.That(result > 0);
        }

        [Test]
        public void UpdateApplication_Test()
        {
            var mgr = new ApplicationManager();
            var entity = new ApplicationEntity();
            entity.Id = 1;
            entity.AppCode = "test_app_code" + DateTime.Now.ToString();
            entity.Description = "this is a test";
            entity.Created = DateTime.Now;
            entity.Modified = DateTime.Now;
            var result = mgr.Update(entity);
            Assert.That(result > 0);
        }
        [Test]
        public void GetApplicationById_Test()
        {
            var mgr = new ApplicationManager();
            ApplicationEntity  result = mgr.GetById(1);
            Assert.That(result.Id > 0);
        }

    }
}
